﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Model;

namespace UtilZ.Dotnet.Ex.Communication.Net.Web
{
    /// <summary>
    /// http响应接口
    /// </summary>
    public interface IHttpResponse
    {
        /// <summary>
        /// http协议版本
        /// </summary>
        string HttpProtocolVer { get; set; }

        /// <summary>
        /// http响应状态值
        /// </summary>
        int StatusCode { get; set; }

        /// <summary>
        /// http连接
        /// </summary>
        HttpConnection Connection { get; }

        /// <summary>
        /// 响应头部
        /// </summary>
        Dictionary<string, string> Headers { get; }

        /// <summary>
        /// 响应扩展头部-用于头中的重复项
        /// </summary>
        List<HeaderItem> ExtendHeaders { get; }

        /// <summary>
        /// 文本编码
        /// </summary>
        Encoding TextEncoding { get; set; }

        /// <summary>
        /// 响应正文数据
        /// </summary>
        DataSource Data { get; set; }

        /// <summary>
        /// 请求范围
        /// </summary>
        List<HttpRequestRange> RequestRangeList { get; set; }

        /// <summary>
        /// 分块发送数据大小
        /// </summary>
        int ChunkSize { get; set; }



        /// <summary>
        /// 添加响应头
        /// </summary>
        /// <param name="headerName">响应头名称</param>
        /// <param name="value">头值</param>
        /// <exception cref="ArgumentNullException">响应头名称等于null将抛出异常</exception>
        void AddHeader(string headerName, string value);

        /// <summary>
        /// 添加响扩展应头
        /// </summary>
        /// <param name="headerItem">http响应头扩展项</param>
        /// <exception cref="ArgumentNullException">响应头名称等于null将抛出异常</exception>
        void AddExtendHeader(HeaderItem headerItem);





        /// <summary>
        /// 设置二进制内容
        /// </summary>
        /// <param name="contentType">http响应内容mime类型</param>
        /// <param name="buffer">内容buffer</param>
        void SetBytes(string contentType, byte[] buffer);

        /// <summary>
        /// 设置文本内容
        /// </summary>
        /// <param name="contentType">内容类型</param>
        /// <param name="text">文本</param>
        void SetTextContent(string contentType, string text);

        /// <summary>
        /// 设置xml内容
        /// </summary>
        /// <param name="xmlStr">xml字符串</param>
        void SetXml(string xmlStr);

        /// <summary>
        /// 设置json内容
        /// </summary>
        /// <param name="json">json</param>
        void SetJSON(string json);

        /// <summary>
        /// 设置文件
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <param name="offset">数据起始偏移位置,小于等于0从头开始</param>
        /// <param name="length">数据长度，小于0到结尾</param>
        void SetFile(string filePath, long offset = -1, long length = -1);





        /// <summary>
        /// http响应方法
        /// </summary>
        /// <param name="stream">写入响应数据对应的流</param>
        void Response(Stream stream);



    }
}
